package cn.lijiguo.concurrency.part1.ch07;

/**
 * SynchronizedStatic
 *
 * @author lijiguo
 * @date 2019/12/16 11:03
 */
public class SynchronizedStatic {

    public static void main(String[] args) {
        new Thread("T1") {
            @Override
            public void run() {
                StaticLock.m1();
            }
        }.start();

        new Thread("T2") {
            @Override
            public void run() {
                StaticLock.m2();
            }
        }.start();
    }
}

class StaticLock {

    public synchronized static void m1() {
        try {
            System.out.println(Thread.currentThread().getName());
            Thread.sleep(5_000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void m2() {
        synchronized (StaticLock.class) {
            try {
                System.out.println(Thread.currentThread().getName());
                Thread.sleep(5_000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
